package online.sanen.mhdt.entity;

import online.sanen.mhdt.constant.AttrConstant;
import online.sanen.mhdt.entity.attr.Attribute;
import online.sanen.mhdt.entity.equip.*;

import java.util.ArrayList;
import java.util.List;

/**
 * 英雄装备
 * @author Administrator
 */
public class HeroEquip {
	private Hero hero;
	private int str;
	private int mag;
	private int con;
	private int vit;
	private int agi;
	/**血*/
	private int hp;
	/**蓝*/
	private int mp;
	/**物攻*/
	private int ad;
	/**法功(灵力)*/
	private int ap;
	/**物防*/
	private int def;
	/**法防*/
	private int magDef;
	/**速度*/
	private int sp;
	private Weapon weapon;
	private Clothes clothes;
	private Cap cap;
	private Shoe shoe;
	private Necklace necklace;
	private Belt belt;
	private List<Attribute> attrList;

	public HeroEquip(Hero hero) {
		this.hero=hero;
		attrList=new ArrayList<>();
	}

	/**
	 * 装备变动，需刷新属性，重新统计
	 */
	public void refreshAttr(){
		this.str=countAppendStr();
		this.mag=countAppendMag();
		this.con=countAppendCon();
		this.vit=countAppendVit();
		this.agi=countAppendAgi();
		this.hp=countAppendHp()+belt.getHp().value;
		this.mp=countAppendMp()+cap.getMp().value;
		this.ad=weapon.getAd().value;
		this.ap=necklace.getAp().value;
		this.def=clothes.getDef().value+cap.getDef().value+belt.getDef().value+shoe.getDef().value;
		this.ap=necklace.getAp().value;
		this.magDef=necklace.getMagDef().value;
		System.out.println(hp);
		System.out.println(mp);
		System.out.println(attrList);
	}
	/**
	 * 刷新装备额外属性集合，每次更换装备需调用
	 */
	public void reflushAttrList(){
		attrList.clear();
		if(weapon!=null&&weapon.getAttrList()!=null)attrList.addAll(weapon.getAttrList());
		if(clothes!=null&&clothes.getAttrList()!=null)attrList.addAll(weapon.getAttrList());
		if(cap!=null&&cap.getAttrList()!=null)attrList.addAll(cap.getAttrList());
		if(necklace!=null&&necklace.getAttrList()!=null)attrList.addAll(necklace.getAttrList());
		if(belt!=null&&belt.getAttrList()!=null)attrList.addAll(belt.getAttrList());
		if(shoe!=null&&shoe.getAttrList()!=null)attrList.addAll(shoe.getAttrList());
		refreshAttr();
	}

	//===================统计装备额外属性===============================
	public int countAppendStr(){
		int sum=0;
		for (Attribute attr:attrList){
			if(attr.type== AttrConstant.TYPE_STR)sum+=attr.value;
		}
		return sum;
	}
	public int countAppendMag(){
		int sum=0;
		for (Attribute attr:attrList){
			if(attr.type== AttrConstant.TYPE_MAG)sum+=attr.value;
		}
		return sum;
	}
	public int countAppendCon(){
		int sum=0;
		for (Attribute attr:attrList){
			if(attr.type== AttrConstant.TYPE_CON)sum+=attr.value;
		}
		return sum;
	}
	public int countAppendVit(){
		int sum=0;
		for (Attribute attr:attrList){
			if(attr.type== AttrConstant.TYPE_VIT)sum+=attr.value;
		}
		return sum;
	}
	public int countAppendAgi(){
		int sum=0;
		for (Attribute attr:attrList){
			if(attr.type== AttrConstant.TYPE_AGI)sum+=attr.value;
		}
		return sum;
	}
	public int countAppendHp(){
		int sum=0;
		for (Attribute attr:attrList){
			if(attr.type== AttrConstant.TYPE_HP)sum+=attr.value;
		}
		return sum;
	}
	public int countAppendMp(){
		int sum=0;
		for (Attribute attr:attrList){
			if(attr.type== AttrConstant.TYPE_MP)sum+=attr.value;
		}
		return sum;
	}
//========================================================
	public int getStr() {
		return str;
	}

	public void setStr(int str) {
		this.str = str;
	}

	public int getMag() {
		return mag;
	}

	public void setMag(int mag) {
		this.mag = mag;
	}

	public int getCon() {
		return con;
	}

	public void setCon(int con) {
		this.con = con;
	}

	public int getVit() {
		return vit;
	}

	public void setVit(int vit) {
		this.vit = vit;
	}

	public int getAgi() {
		return agi;
	}

	public void setAgi(int agi) {
		this.agi = agi;
	}

	public int getHp() {
		return hp;
	}

	public void setHp(int hp) {
		this.hp = hp;
	}

	public int getMp() {
		return mp;
	}

	public void setMp(int mp) {
		this.mp = mp;
	}

	public int getAd() {
		return ad;
	}

	public void setAd(int ad) {
		this.ad = ad;
	}

	public int getAp() {
		return ap;
	}

	public void setAp(int ap) {
		this.ap = ap;
	}

	public int getDef() {
		return def;
	}

	public void setDef(int def) {
		this.def = def;
	}

	public int getMagDef() {
		return magDef;
	}

	public void setMagDef(int magDef) {
		this.magDef = magDef;
	}

	public int getSp() {
		return sp;
	}

	public void setSp(int sp) {
		this.sp = sp;
	}

	public Weapon getWeapon() {
		return weapon;
	}

	public void setWeapon(Weapon weapon) {
		this.weapon = weapon;
	}

	public Clothes getClothes() {
		return clothes;
	}

	public void setClothes(Clothes clothes) {
		this.clothes = clothes;
	}

	public Cap getCap() {
		return cap;
	}

	public void setCap(Cap cap) {
		this.cap = cap;
	}

	public Shoe getShoe() {
		return shoe;
	}

	public void setShoe(Shoe shoe) {
		this.shoe = shoe;
	}

	public Necklace getNecklace() {
		return necklace;
	}

	public void setNecklace(Necklace necklace) {
		this.necklace = necklace;
	}

	public Belt getBelt() {
		return belt;
	}

	public void setBelt(Belt belt) {
		this.belt = belt;
	}
}
